﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Guline.Hoster.Controllers
{
    public class GroupController : BaseController
    {
        public ActionResult jsonList()
        {
            return Json(this.db.HostPackages, JsonRequestBehavior.AllowGet);
        }

        public ActionResult Index()
        {
            return View(this.db.Groups);
        }
        public ActionResult Create()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Create(Guline.HosterModels.Object.Group model)
        {
            if (ModelState.IsValid)
            {
                this.db.Groups.Add(model);
                this.db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View();
        }
        public ActionResult Edit(int ID)
        {
            var group = db.Groups.Where(m => m.ID == ID).FirstOrDefault();
            return View(group);
        }
        [HttpPost]
        public ActionResult Edit(Guline.HosterModels.Object.Group model)
        {
            if (ModelState.IsValid)
            {

                db.Entry(model).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View();
        }

        public ActionResult Delete(int GroupID)
        {
            var group = db.Groups.Where(m => m.ID == GroupID).FirstOrDefault();
            db.Groups.Remove(group);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        public ActionResult editStatus(int GroupID)
        {
            var group = db.Groups.Where(m => m.ID == GroupID).FirstOrDefault();
            if (group.Status == 0)
            {
                group.Status = 1;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            else
            {
                group.Status = 0;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
        }

    }
}
